
#include <iostream>
#include<unistd.h>//unix stand lib
#include<sys/types.h>
#include<sys/fcntl.h>
#include<sys/stat.h>
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#include<dirent.h>//file dir
#include <sys/wait.h>//wait func
#include <stdlib.h>//ststem
#include <signal.h>
#include <string.h>
#include <sys/msg.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#include "msg_type.h"

using namespace std;


//====================================queue
int main(int argc, char *argv[])
{
    struct timespec time1 = {0, 0}; 
    struct timespec time2 = {0, 0};

    float temp;

	int msg_id;
	msg_id = msgget((key_t)1122, IPC_CREAT | 0666);
	if (msg_id == -1)
	{
		perror("msgget error:");
	}
	
	MSG_DATA msginfo;
	
	strcpy(msginfo.message, "hello message!");
    clock_gettime(CLOCK_REALTIME, &time1);

    for(int nloop=0;nloop<def_TEST_CNT;nloop++)
    {
        msginfo.mtype = nloop+5;//指定mtype
        if(msgsnd(msg_id,&msginfo,sizeof(msginfo.message),0)==-1)
        {
            perror("message send error:");
        }
    }

    clock_gettime(CLOCK_REALTIME, &time2);
        temp = (time2.tv_nsec - time1.tv_nsec) ;
        long seconds = time2.tv_sec - time1.tv_sec;
        long nanoseconds = time2.tv_nsec - time1.tv_nsec;
        printf("Elapsed time: %ld seconds, %ld nanoseconds\n", seconds, nanoseconds);

        printf("time = %f ns\n", temp); 	

	cout << "message send success" << endl;
	return 0;
}
